"use client"

import { Share } from "lucide-react"
import { Button } from "@/components/ui/button"
import { shareResource, type ShareableResource } from "@/lib/share-service"
import { toast } from "@/components/ui/use-toast"

interface ShareButtonProps {
    resource: ShareableResource
    variant?: "default" | "secondary" | "outline" | "ghost" | "link"
    size?: "default" | "sm" | "lg" | "icon"
    className?: string
    showText?: boolean
}

export function ShareButton({
                                resource,
                                variant = "ghost",
                                size = "icon",
                                className,
                                showText = false,
                            }: ShareButtonProps) {
    const handleShare = () => {
        shareResource(resource)
        toast({
            title: "准备分享",
            description: `正在前往分享页面: ${resource.title}`,
        })
    }

    return (
        <Button variant={variant} size={size} className={className} onClick={handleShare} aria-label="分享">
            <Share className="h-4 w-4 mr-2" />
            {showText && "分享"}
        </Button>
    )
}

